/**
 * Malsha 2014/11/10
 */

RepCustomerInvestment = new Object();

var investments_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'invenstmentCode', 'amount', 'fundTransferType', 'status', 'requestDate', 'customer', 'depositTo', 'fullRedemption', 'fullRedemptionDate',
			'monthlyInterestRequired', 'investmentinterestType', 'monIntStartDate', 'nameOfBank', 'branch', 'chequeNo', 'chequeDate', 'accountNo', 'recodUser', 'customer_name',
			'fund_id', 'confirmDate', 'unitPrice', 'noOfUnits' ]
});
var customer_account_store = Ext.create('Ext.data.Store', {
	fields : [ 'accountNo', 'branch', 'nameOfBank', 'customer', 'id' ]
});
var customer_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'code', 'title', 'initials', 'surname', 'denotedByInitials', 'nicPassport', 'customerType', 'accountType', 'residential', 'fmId', 'correspondingAddress',
			'generalAddress', 'phone', 'fax', 'corresEmail', 'corresFax', 'corresPost', 'corresInst', 'bankInstrution', 'organizationName', 'businessRegNo', 'businessAddress' ]
});

var inv_fund_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'name', 'code', 'unitValue', 'updateDate' ]
});

RepCustomerInvestment.getBasicDetails = function() {
	return Ext.create('Ext.form.FieldSet', {

		defaults : {
			anchor : '100%'
		},
		items : [ {
			xtype : 'combo',
			fieldLabel : 'Fund<span style="color:red">*</span>',
			labelWidth : 110,
			anchor : '70%',
			store : inv_fund_store,
			valueField : 'id',
			displayField : 'code',
			allowBlank : false,
			msgTarget : 'under',
			emptyText : 'Select a Fund...',
			isLoaded : false,
			editable : false,
			name : 'fund_id',
			tpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '<div class="x-boundlist-item">{code} - {name}</div>', '</tpl>'),
			displayTpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '{code} - {name}', '</tpl>'),
			listeners : {
				expand : function(combo, opt) {
					if (!combo.isLoaded) {
						Ext.Ajax.request({
							url : 'getFundVsUnitValue.action',
							success : function(response) {
								var obj = Ext.decode(response.responseText);
								combo.getStore().loadRawData(obj.fundDtos);
								combo.isLoaded = true;
							}
						});
					}
				},
				change : function(combo, record, index) {
					if (combo.getValue() == "" || combo.getValue() == "&nbsp;" || combo.getValue == 0)
						combo.setValue(null);
				}
			}
		}, {
			xtype : 'combo',
			labelWidth : 110,
			anchor : '40%',
			fieldLabel : 'Status',
			store : Ext.create('Ext.data.Store', {
				fields : [ 'svalue', 'status' ],
				data : [ {
					"svalue" : "A",
					"status" : "ALL"
				}, {
					"svalue" : "I",
					"status" : "INITIAL"
				}, {
					"svalue" : "C",
					"status" : "CONFIRM"
				}, {
					"svalue" : "R",
					"status" : "REJECT"
				}, {
					"svalue" : "S",
					"status" : "CANCEL"
				} ]
			}),
			value : 'A',
			name : 'status',
			valueField : 'svalue',
			displayField : 'status',
		}, {
			xtype : 'fieldcontainer',
			layout : 'hbox',
			labelWidth : 110,
			fieldLabel : 'Request Date',
			items : [ {
				xtype : 'datefield',
				fieldLabel : 'From',
				name : 'requestDateFrom',
				labelWidth : 40,
				padding : '0 15 0 0',
				flex : 1
			}, {
				xtype : 'datefield',
				fieldLabel : 'To',
				name : 'requestDateTo',
				labelWidth : 20,
				flex : 1
			} ]
		}, {
			xtype : 'combo',
			labelWidth : 110,
			anchor : '40%',
			fieldLabel : 'Fund Transfer',
			store : Ext.create('Ext.data.Store', {
				fields : [ 'ftvalue', 'type' ],
				data : [ {
					"ftvalue" : "A",
					"type" : "ALL"
				}, {
					"ftvalue" : "I",
					"type" : "RTGS"
				}, {
					"ftvalue" : "C",
					"type" : "SLIP"
				}, {
					"ftvalue" : "R",
					"type" : "CASH"
				}, {
					"ftvalue" : "S",
					"type" : "CHEQUE"
				} ]
			}),
			value : 'A',
			valueField : 'ftvalue',
			displayField : 'type',
		}, {
			xtype : 'combo',
			labelWidth : 110,
			anchor : '40%',
			fieldLabel : 'Deposit To',
			store : Ext.create('Ext.data.Store', {
				fields : [ 'dtvalue', 'type' ],
				data : [ {
					"dtvalue" : "A",
					"type" : "ALL"
				}, {
					"dtvalue" : "D",
					"type" : "Custodian Account"
				}, {
					"dtvalue" : "C",
					"type" : "CALI Account"
				} ]
			}),
			value : 'A',
			valueField : 'dtvalue',
			displayField : 'type',
		}, {
			xtype : 'combo',
			labelWidth : 110,
			store : customer_store,
			valueField : 'id',
			displayField : 'code',
			fieldLabel : 'Customer',
			anchor : '70%',
			id : 'customer',
			name : 'customer',
			queryMode : 'local',
			isLoaded : false,
			tpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '<div class="x-boundlist-item">{code} - {surname}</div>', '</tpl>'),
			displayTpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '{code} - {surname}', '</tpl>'),
			listeners : {
				expand : function(combo, opt) {
					if (!combo.isLoaded) {
						Ext.Ajax.request({
							url : 'getCustomer.action',
							success : function(response) {
								var obj = Ext.decode(response.responseText);
								combo.getStore().loadRawData(obj.customerBeans);
								combo.isLoaded = true;
							}
						});
					}
				}
			}
		} ]
	});
};

RepCustomerInvestment.getCenterPanel = function() {

	var feilds = RepCustomerInvestment.getBasicDetails();
	formpanel = Ext.create('Ext.form.Panel', {
		title : 'Customer Investment',
		bodyPadding : 20,
		autoScroll : true,
		frame : true,
		defaults : {
			labelWidth : 110,
			anchor : '65%',
		},
		items : [ feilds ],
		buttonAlign : 'center',
		buttons : [ {
			text : 'Cancel',
			handler : function() {
				App.Core.removeScreen();
			}
		}, {
			text : 'Reset',
			handler : function() {
			}
		}, {
			text : 'Print',
			handler : function() {
			}
		} ],
		listeners : {}
	});
	return formpanel;

};
